package com.zhl.interface_Demo8;

import java.util.ArrayList;

public class StudentOperatorIpml2 implements StudentOperator {
    @Override
    public void printAllStudents(ArrayList<Student> students) {
        System.out.println("====全班学生信息====");
        int count_male = 0;
        int count_female = 0;
        for(int i=0;i<students.size();i++){
            Student s = students.get(i);
            if(s.getSex()=='男'){
                count_male++;
            }else{
                count_female++;
            }
            System.out.println("姓名："+s.getName()+"  分数："+s.getScore()+"  性别："+s.getSex());
        }
        System.out.println("男生数量："+count_male+"  女生数量："+count_female);
        System.out.println("班级总人数是:"+students.size());
    }

    @Override
    public void printAvergeScore(ArrayList<Student> students) {
        System.out.println("====全班学生平均分数====");
        double allscore = 0;
        double max = 0;
        double min = 100;
        for(int i=0;i<students.size();i++){
            Student s = students.get(i);
            if(s.getScore()>max){
                max = s.getScore();
            }
            if(s.getScore()<min){
                min = s.getScore();
            }
            allscore += s.getScore();
        }
        double averge = (allscore-max-min)/(students.size()-2);
        System.out.println("平均分数："+averge);
    }
}
